package com.sample.navigation.fragment;

import android.os.Bundle;
import android.text.TextPaint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.sample.navigation.MainActivity;
import com.sample.navigation.R;
import com.sample.navigation.fragment.dialog.FragmentDialogBottom;
import com.sample.navigation.fragment.dialog.FragmentDialogProgress;
import com.sample.navigation.layout.RoundRectLayout;
import com.sample.navigation.view.BoldTextView;

import androidx.fragment.app.Fragment;

public class Fragment1 extends Fragment {
    private View rootView;
    private boolean hasFront = false;
    private boolean hasBack = false;
    private RoundRectLayout btnSubmit;
    private BoldTextView textSubmit;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_1, null);
        initComponents();
        return rootView;
    }

    private void initComponents(){
        FragmentDialogProgress dialogProgress = new FragmentDialogProgress(this);
        btnSubmit = (RoundRectLayout)rootView.findViewById(R.id.btn_submit);
        btnSubmit.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialogProgress.show(getChildFragmentManager(), FragmentDialogBottom.class.getSimpleName());
                        //此处设置为true表示点击灰色区域退出
                        //如果不需要点击灰色区域退出请设置为false
                        dialogProgress.setCancelable(false);
                    }
                });
        textSubmit = (BoldTextView)rootView.findViewById(R.id.text_submit);
        rootView.findViewById(R.id.upload_front)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if(true){
                            rootView.findViewById(R.id.front_finish)
                                    .setVisibility(View.VISIBLE);
                            hasFront = true;
                            checkSubmit();
                        }
                    }
                });
        rootView.findViewById(R.id.upload_back)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if(true){
                            rootView.findViewById(R.id.back_finish)
                                    .setVisibility(View.VISIBLE);
                            hasBack = true;
                            checkSubmit();
                        }
                    }
                });
    }

    private void checkSubmit(){
        if(hasFront && hasBack){
            btnSubmit.setEnabled(true);
            btnSubmit.setBackgroundColor(getResources().getColor(R.color.bg_active), getResources().getColor(R.color.bg_active));
            textSubmit.setTextColor(getResources().getColor(R.color.text_color_white));
        }else{
            btnSubmit.setEnabled(false);
            btnSubmit.setBackgroundColor(getResources().getColor(R.color.bg_inactive), getResources().getColor(R.color.bg_inactive));
            textSubmit.setTextColor(getResources().getColor(R.color.text_color_inactive));
        }
    }

    public void switchToNext(){
        ((MainActivity)getActivity()).switchToNext(1);
    }
}
